package com.itheima.job.test04;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class TCPServer {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(12345);
        Socket socket = ss.accept();
        InputStream is = socket.getInputStream();
        OutputStream os = socket.getOutputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
        while (true) {
            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
            if ("exit".equals(line)){
                break;
            }

            bw.write("为所欲为");
            bw.newLine();
            bw.flush();
        }
        br.close();
        bw.close();
        socket.close();
        ss.close();

    }
}
